package org.offsync.async
import java.util.concurrent.atomic.AtomicBoolean

object Functions {
  def onceOnly(task: (() => Unit) => Unit): (() => Unit) => Unit = {
    val completed = new AtomicBoolean(false)
    return { completion: (() => Unit) =>
      if (!completed.getAndSet(true)) {
        task(completion)
      }
    }
  }
}
